package com.sebiotec.login.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import com.alibaba.android.arouter.launcher.ARouter;
import com.allen.library.base.BaseHttpUtil;
import com.allen.library.interceptor.Transformer;
import com.allen.library.observer.CommonObserver;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.GsonUtil;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.login.R;
import com.sebiotec.login.model.Test;
import com.sebiotec.login.model.TestResponse;
import com.sebiotec.login.model.get.UpdateApp;
import com.sebiotec.login.net.RadomApiHelper;

import okhttp3.RequestBody;

public class SplashActivity extends BaseActivity {



    @Override
    protected int setLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initUI() {
//
//        Test  test =new Test();
//
//        String json = GsonUtil.getGson().toJson(test);
//        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), json);
//
//        RadomApiHelper.geRadomApi()
//                .test(body)
//                .compose(Transformer.<TestResponse>switchSchedulers())
//                .subscribe(new CommonObserver<TestResponse>() {
//                    @Override
//                    protected void onError(String errorMsg) {
//
//                    }
//
//                    @Override
//                    protected void onSuccess(TestResponse s) {
//
//                    }
//                });


        if (getIntent().hasExtra("story_id")) {
            Bundle bundle = new Bundle();        //得到bundle对象
            bundle.putString("tz", "11");
            Log.d("Login", "进来了");
            if (!TextUtils.isEmpty(SPUtils.get(SjmConstant.TOKEN, ""))) {
                if (1 == SPUtils.get(SjmConstant.ROLEID, 0)) {
                    Log.d("Login", "进来了1");
                    ARouter.getInstance().build("/App/MainActivity").withBundle("bundle", bundle).navigation();
                    ActivityTool.getInstance().popOneActivity(SplashActivity.this);
                    return;
                } else if (3 == SPUtils.get(SjmConstant.ROLEID, 0)) {
                    Log.d("Login", "进来了2");
                    ARouter.getInstance().build("/App/JobMainActivity").withBundle("bundle", bundle).navigation();
                    ActivityTool.getInstance().popOneActivity(SplashActivity.this);

                    return;
                } else if (5 == SPUtils.get(SjmConstant.ROLEID, 0)) {
                    Log.d("Login", "进来了3");
                    ARouter.getInstance().build("/App/ManagerMainActivity").withBundle("bundle", bundle).navigation();
                    ActivityTool.getInstance().popOneActivity(SplashActivity.this);
                    return;
                }
            } else {
                return;
            }

        } else {
            Thread myThread = new Thread() {//创建子线程
                @Override
                public void run() {
                    try {
                        sleep(1000);//使程序休眠一秒

                        Intent it = new Intent(getApplicationContext(), LoginActivity.class);
                        startActivity(it);
                        ActivityTool.getInstance().finishActivity(SplashActivity.this);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            myThread.start();//启动线程
        }

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {

    }
}
